Completed
Push — master ( 2813c1...14a1cb )
by Maxence
01:59
created

$(document).ready   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 3
nc 2
nop 1
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
27
/** global: OC */
28
29
var elements = {
30
	test_async_start: null,
31
	test_async_reset: null,
32
	test_async_wait: null,
33
	allow_linked_groups: null,
34
	allow_federated_circles: null
35
};
36
37
38
$(document).ready(function () {
39
40
	elements.test_async_start = $('#test_async_start');
41
	elements.test_async_reset = $('#test_async_reset');
42
	elements.test_async_wait = $('#test_async_wait');
43
	elements.test_async_result = $('#test_async_result');
44
	elements.allow_linked_groups = $('#allow_linked_groups');
45
	elements.allow_federated_circles = $('#allow_federated_circles');
46
47
	elements.test_async_wait.hide().on('click', function () {
48
		self.refreshResult();
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
	});
50
51
	elements.test_async_reset.hide().on('click', function () {
52
		$.ajax({
53
			method: 'DELETE',
54
			url: OC.generateUrl('/apps/circles/admin/testAsync')
55
		}).done(function (res) {
56
			self.displayTestAsync(res);
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
57
		});
58
	});
59
60
	elements.test_async_start.hide().on('click', function () {
61
		$.ajax({
62
			method: 'POST',
63
			url: OC.generateUrl('/apps/circles/admin/testAsync')
64
		}).done(function (res) {
65
			self.displayTestAsync(res);
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
66
		});
67
	});
68
69
	elements.allow_linked_groups.on('change', function () {
70
		saveChange();
71
	});
72
73
	elements.allow_federated_circles.on('change', function () {
74
		saveChange();
75
	});
76
77
	saveChange = function () {
0 ignored issues
show
Bug introduced by
The variable saveChange seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.saveChange.
Loading history...
78
		$.ajax({
79
			method: 'POST',
80
			url: OC.generateUrl('/apps/circles/admin/settings'),
81
			data: {
82
				allow_linked_groups: (elements.allow_linked_groups.is(
83
					':checked')) ? '1' : '0',
84
				allow_federated_circles: (elements.allow_federated_circles.is(
85
					':checked')) ? '1' : '0'
86
			}
87
		}).done(function (res) {
88
			elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1'));
89
			elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1'));
90
		});
91
	};
92
93
	updateTestAsync = function () {
0 ignored issues
show
Bug introduced by
The variable updateTestAsync seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.updateTestAsync.
Loading history...
94
		self.refreshResult();
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
95
	};
96
97
98
	refreshResult = function () {
0 ignored issues
show
Bug introduced by
The variable refreshResult seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.refreshResult.
Loading history...
99
		$.ajax({
100
			method: 'GET',
101
			url: OC.generateUrl('/apps/circles/admin/testAsync')
102
		}).done(function (res) {
103
			self.displayTestAsync(res);
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
104
		});
105
	};
106
107
	displayTestAsync = function (res) {
0 ignored issues
show
Bug introduced by
The variable displayTestAsync seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.displayTestAsync.
Loading history...
108
		console.log('____' + JSON.stringify(res));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
109
		displayTestAsyncResult(res);
110
		displayTestAsyncNewTest(res);
111
		displayTestAsyncReset(res);
112
		displayTestAsyncWait(res);
113
	};
114
115
116
	displayTestAsyncResult = function (res) {
0 ignored issues
show
Bug introduced by
The variable displayTestAsyncResult seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.displayTestAsyncResult.
Loading history...
117
		if (res.init !== '0') {
118
			if (res.test.running === 0) {
119
				elements.test_async_result.text(
120
					'Test is now over; final score: ' + res.test.note);
121
				return;
122
			}
123
124
125
			elements.test_async_result.text(
126
				'Test is running. current tick: ' + res.count + '/121');
127
128
			return;
129
		}
130
131
		elements.test_async_result.text(
132
			t('circles', 'Circles is using its own way to async heavy process.'));
133
	};
134
135
136
	displayTestAsyncNewTest = function (res) {
0 ignored issues
show
Bug introduced by
The variable displayTestAsyncNewTest seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.displayTestAsyncNewTest.
Loading history...
137
		if (res.init !== '' && res.init !== '0') {
138
			elements.test_async_start.hide();
139
			return;
140
		}
141
142
		elements.test_async_start.show();
143
	};
144
145
	displayTestAsyncReset = function (res) {
0 ignored issues
show
Bug introduced by
The variable displayTestAsyncReset seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.displayTestAsyncReset.
Loading history...
146
		if (res.init !== '' && res.init !== '0') {
147
			elements.test_async_reset.show();
148
			return;
149
		}
150
151
		elements.test_async_reset.hide();
152
	};
153
154
	displayTestAsyncWait = function (res) {
0 ignored issues
show
Bug introduced by
The variable displayTestAsyncWait seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.displayTestAsyncWait.
Loading history...
155
		if (Number(res.test.running) === 1) {
156
			elements.test_async_reset.hide();
157
			elements.test_async_start.hide();
158
			elements.test_async_wait.show();
159
			return;
160
		}
161
162
		elements.test_async_wait.hide();
163
	};
164
165
166
	$.ajax({
167
		method: 'GET',
168
		url: OC.generateUrl('/apps/circles/admin/settings'),
169
		data: {}
170
	}).done(function (res) {
171
		elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1'));
172
		elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1'));
173
	});
174
175
	var timerTestAsync = setInterval(function () {
0 ignored issues
show
Unused Code introduced by
The variable timerTestAsync seems to be never used. Consider removing it.
Loading history...
176
		self.updateTestAsync();
0 ignored issues
show
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
177
	}, 4000);
178
179
180
})
181
;